import Vue from "vue";
import Vuex from "vuex";

function getRandomId() {
  return `node_${new Date().getTime().toString().substring(5)}${Math.round(
    Math.random() * 9000 + 1000
  )}`;
}

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    processType: "", // 审批配置的类型
    nodeMap: new Map(),
    selectedNode: {},
    addBtnUseable: true, // 添加按钮是否可用
    delBtnUseable: true, // 删除按钮是否可用
    process: {
      id: "root",
      parentId: null,
      type: "ROOT",
      name: "发起人",
      props: {
        assignedUser: [],
        isShow: null,
      },
      children: {
        id: getRandomId(),
        parentId: "root",
        type: "APPROVAL",
        name: "审批人1",
        props: {
          assignedUser: [],
          isShow: null,
        },
        children: {},
      },
    },
  },
  mutations: {
    selectedNode(state, val) {
      state.selectedNode = val;
    },
    setProcessType(state, processType) {
      state.processType = processType;
    },
    setAddBtn(state, flag) {
      state.addBtnUseable = flag;
    },
    setDelBtn(state, flag) {
      state.delBtnUseable = flag;
    },
  },
});
